// pages/myJob/myJob.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    key: 1,
    list: []
  },

  // 查看菜单
  changMenu: function (e) {
    app.post('Member/mywork', {
      state: e.currentTarget.dataset.key,
      token: wx.getStorageSync('token')
    }).then(res => {
      this.setData({
        list: res.data,
        key: e.currentTarget.dataset.key
      })
    })
  },

  //拒绝承接
  refuse: function (e) {
    wx.showModal({
      title: '提示',
      content: '确定拒绝承接?',
      success: res => {
        if (res.confirm) {
          app.post('Member/refuse', {
            id: e.currentTarget.dataset.cid
          }).then(res => {
            wx.navigateTo({
              url: '/pages/state/state?state=1',
            })
          })
          this.onLoad()
        }
      }
    })
  },

  // 同意接单
  agree: function (e) {
    wx.showModal({
      title: '提示',
      content: '确定同意接单?',
      success: res => {
        if (res.confirm) {
          app.post('Member/confirm', {
            id: e.currentTarget.dataset.cid
          }).then(res => {
            wx.navigateTo({
              url: '/pages/state/state?state=1',
            })
          })
          this.onLoad()
        }
      }
    })
  },

  // 提交完成
  finish: function (e) {
    wx.showModal({
      title: '提示',
      content: '确定提交完成?',
      success: res => {
        if (res.confirm) {
          app.post('Member/complete', {
            id: e.currentTarget.dataset.cid
          }).then(res => {
            wx.navigateTo({
              url: '/pages/state/state?state=1',
            })
          })
          this.onLoad()
        }
      }
    })
  },

  // 去评价
  evaluate: function (e) {
    wx.navigateTo({
      url: '/pages/evaluate/evaluate?id=' + e.currentTarget.dataset.cid,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#284A6C',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
    app.post('Member/mywork', {
      state: that.data.key,
      token: wx.getStorageSync('token')
    }).then(res => {
      console.log(res.data)
      that.setData({
        list: res.data
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.onLoad()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})